﻿using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.Serialization;

namespace HalconDotNet
{
	/// <summary>Represents an instance of a variation model.</summary>
	// Token: 0x02000070 RID: 112
	[Serializable]
	public class HVariationModel : HHandle, ISerializable, ICloneable
	{
		// Token: 0x06001AA8 RID: 6824 RVA: 0x0000883B File Offset: 0x00006A3B
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HVariationModel() : base(HHandleBase.UNDEF)
		{
		}

		// Token: 0x06001AA9 RID: 6825 RVA: 0x000A50CE File Offset: 0x000A32CE
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HVariationModel(IntPtr handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06001AAA RID: 6826 RVA: 0x000A50DD File Offset: 0x000A32DD
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HVariationModel(HHandle handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06001AAB RID: 6827 RVA: 0x000A50EC File Offset: 0x000A32EC
		private void AssertSemType()
		{
			base.AssertSemType("variation_model");
		}

		// Token: 0x06001AAC RID: 6828 RVA: 0x000A50F9 File Offset: 0x000A32F9
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HVariationModel obj)
		{
			obj = new HVariationModel(HHandleBase.UNDEF);
			return obj.Load(proc, parIndex, err);
		}

		// Token: 0x06001AAD RID: 6829 RVA: 0x000A5114 File Offset: 0x000A3314
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HVariationModel[] obj)
		{
			HTuple htuple;
			err = HTuple.LoadNew(proc, parIndex, err, out htuple);
			obj = new HVariationModel[htuple.Length];
			for (int i = 0; i < htuple.Length; i++)
			{
				obj[i] = new HVariationModel(HalconAPI.IsLegacyHandleMode() ? htuple[i].IP : htuple[i].H);
			}
			htuple.Dispose();
			return err;
		}

		/// <summary>
		///   Read a variation model from a file.
		///   Modified instance represents: ID of the variation model.
		/// </summary>
		/// <param name="fileName">File name.</param>
		// Token: 0x06001AAE RID: 6830 RVA: 0x000A5184 File Offset: 0x000A3384
		public HVariationModel(string fileName)
		{
			IntPtr proc = HalconAPI.PreCall(83);
			HalconAPI.StoreS(proc, 0, fileName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Create a variation model for image comparison.
		///   Modified instance represents: ID of the variation model.
		/// </summary>
		/// <param name="width">Width of the images to be compared. Default: 640</param>
		/// <param name="height">Height of the images to be compared. Default: 480</param>
		/// <param name="type">Type of the images to be compared. Default: "byte"</param>
		/// <param name="mode">Method used for computing the variation model. Default: "standard"</param>
		// Token: 0x06001AAF RID: 6831 RVA: 0x000A51D0 File Offset: 0x000A33D0
		public HVariationModel(int width, int height, string type, string mode)
		{
			IntPtr proc = HalconAPI.PreCall(95);
			HalconAPI.StoreI(proc, 0, width);
			HalconAPI.StoreI(proc, 1, height);
			HalconAPI.StoreS(proc, 2, type);
			HalconAPI.StoreS(proc, 3, mode);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		// Token: 0x06001AB0 RID: 6832 RVA: 0x000A5234 File Offset: 0x000A3434
		void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
		{
			HSerializedItem hserializedItem = this.SerializeVariationModel();
			byte[] value = hserializedItem;
			hserializedItem.Dispose();
			info.AddValue("data", value, typeof(byte[]));
		}

		// Token: 0x06001AB1 RID: 6833 RVA: 0x000A526C File Offset: 0x000A346C
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HVariationModel(SerializationInfo info, StreamingContext context)
		{
			HSerializedItem hserializedItem = new HSerializedItem((byte[])info.GetValue("data", typeof(byte[])));
			this.DeserializeVariationModel(hserializedItem);
			hserializedItem.Dispose();
		}

		/// <summary>Serialize object to binary stream in HALCON format</summary>
		// Token: 0x06001AB2 RID: 6834 RVA: 0x000A52AC File Offset: 0x000A34AC
		public new void Serialize(Stream stream)
		{
			HSerializedItem hserializedItem = this.SerializeVariationModel();
			hserializedItem.Serialize(stream);
			hserializedItem.Dispose();
		}

		/// <summary>Deserialize object from binary stream in HALCON format</summary>
		// Token: 0x06001AB3 RID: 6835 RVA: 0x000A52C0 File Offset: 0x000A34C0
		public new static HVariationModel Deserialize(Stream stream)
		{
			HVariationModel hvariationModel = new HVariationModel();
			HSerializedItem hserializedItem = HSerializedItem.Deserialize(stream);
			hvariationModel.DeserializeVariationModel(hserializedItem);
			hserializedItem.Dispose();
			return hvariationModel;
		}

		// Token: 0x06001AB4 RID: 6836 RVA: 0x000A52E6 File Offset: 0x000A34E6
		object ICloneable.Clone()
		{
			return this.Clone();
		}

		// Token: 0x06001AB5 RID: 6837 RVA: 0x000A52F0 File Offset: 0x000A34F0
		public new HVariationModel Clone()
		{
			HSerializedItem hserializedItem = this.SerializeVariationModel();
			HVariationModel hvariationModel = new HVariationModel();
			hvariationModel.DeserializeVariationModel(hserializedItem);
			hserializedItem.Dispose();
			return hvariationModel;
		}

		/// <summary>
		///   Deserialize a variation model.
		///   Modified instance represents: ID of the variation model.
		/// </summary>
		/// <param name="serializedItemHandle">Handle of the serialized item.</param>
		// Token: 0x06001AB6 RID: 6838 RVA: 0x000A5318 File Offset: 0x000A3518
		public void DeserializeVariationModel(HSerializedItem serializedItemHandle)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(81);
			HalconAPI.Store(proc, 0, serializedItemHandle);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(serializedItemHandle);
		}

		/// <summary>
		///   Serialize a variation model.
		///   Instance represents: ID of the variation model.
		/// </summary>
		/// <returns>Handle of the serialized item.</returns>
		// Token: 0x06001AB7 RID: 6839 RVA: 0x000A5368 File Offset: 0x000A3568
		public HSerializedItem SerializeVariationModel()
		{
			IntPtr proc = HalconAPI.PreCall(82);
			base.Store(proc, 0);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HSerializedItem result;
			num = HSerializedItem.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Read a variation model from a file.
		///   Modified instance represents: ID of the variation model.
		/// </summary>
		/// <param name="fileName">File name.</param>
		// Token: 0x06001AB8 RID: 6840 RVA: 0x000A53B0 File Offset: 0x000A35B0
		public void ReadVariationModel(string fileName)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(83);
			HalconAPI.StoreS(proc, 0, fileName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Write a variation model to a file.
		///   Instance represents: ID of the variation model.
		/// </summary>
		/// <param name="fileName">File name.</param>
		// Token: 0x06001AB9 RID: 6841 RVA: 0x000A53FC File Offset: 0x000A35FC
		public void WriteVariationModel(string fileName)
		{
			IntPtr proc = HalconAPI.PreCall(84);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, fileName);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Return the threshold images used for image comparison by a variation model.
		///   Instance represents: ID of the variation model.
		/// </summary>
		/// <param name="maxImage">Threshold image for the upper threshold.</param>
		/// <returns>Threshold image for the lower threshold.</returns>
		// Token: 0x06001ABA RID: 6842 RVA: 0x000A5438 File Offset: 0x000A3638
		public HImage GetThreshImagesVariationModel(out HImage maxImage)
		{
			IntPtr proc = HalconAPI.PreCall(85);
			base.Store(proc, 0);
			HalconAPI.InitOCT(proc, 1);
			HalconAPI.InitOCT(proc, 2);
			int num = HalconAPI.CallProcedure(proc);
			HImage result;
			num = HImage.LoadNew(proc, 1, num, out result);
			num = HImage.LoadNew(proc, 2, num, out maxImage);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Return the images used for image comparison by a variation model.
		///   Instance represents: ID of the variation model.
		/// </summary>
		/// <param name="varImage">Variation image of the trained object.</param>
		/// <returns>Image of the trained object.</returns>
		// Token: 0x06001ABB RID: 6843 RVA: 0x000A5490 File Offset: 0x000A3690
		public HImage GetVariationModel(out HImage varImage)
		{
			IntPtr proc = HalconAPI.PreCall(86);
			base.Store(proc, 0);
			HalconAPI.InitOCT(proc, 1);
			HalconAPI.InitOCT(proc, 2);
			int num = HalconAPI.CallProcedure(proc);
			HImage result;
			num = HImage.LoadNew(proc, 1, num, out result);
			num = HImage.LoadNew(proc, 2, num, out varImage);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Compare an image to a variation model.
		///   Instance represents: ID of the variation model.
		/// </summary>
		/// <param name="image">Image of the object to be compared.</param>
		/// <param name="mode">Method used for comparing the variation model. Default: "absolute"</param>
		/// <returns>Region containing the points that differ substantially from the model.</returns>
		// Token: 0x06001ABC RID: 6844 RVA: 0x000A54E8 File Offset: 0x000A36E8
		public HRegion CompareExtVariationModel(HImage image, string mode)
		{
			IntPtr proc = HalconAPI.PreCall(87);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, image);
			HalconAPI.StoreS(proc, 1, mode);
			HalconAPI.InitOCT(proc, 1);
			int num = HalconAPI.CallProcedure(proc);
			HRegion result;
			num = HRegion.LoadNew(proc, 1, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(image);
			return result;
		}

		/// <summary>
		///   Compare an image to a variation model.
		///   Instance represents: ID of the variation model.
		/// </summary>
		/// <param name="image">Image of the object to be compared.</param>
		/// <returns>Region containing the points that differ substantially from the model.</returns>
		// Token: 0x06001ABD RID: 6845 RVA: 0x000A5544 File Offset: 0x000A3744
		public HRegion CompareVariationModel(HImage image)
		{
			IntPtr proc = HalconAPI.PreCall(88);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, image);
			HalconAPI.InitOCT(proc, 1);
			int num = HalconAPI.CallProcedure(proc);
			HRegion result;
			num = HRegion.LoadNew(proc, 1, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(image);
			return result;
		}

		/// <summary>
		///   Prepare a variation model for comparison with an image.
		///   Instance represents: ID of the variation model.
		/// </summary>
		/// <param name="refImage">Reference image of the object.</param>
		/// <param name="varImage">Variation image of the object.</param>
		/// <param name="absThreshold">Absolute minimum threshold for the differences between the image and the variation model. Default: 10</param>
		/// <param name="varThreshold">Threshold for the differences based on the variation of the variation model. Default: 2</param>
		// Token: 0x06001ABE RID: 6846 RVA: 0x000A5598 File Offset: 0x000A3798
		public void PrepareDirectVariationModel(HImage refImage, HImage varImage, HTuple absThreshold, HTuple varThreshold)
		{
			IntPtr proc = HalconAPI.PreCall(89);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, refImage);
			HalconAPI.Store(proc, 2, varImage);
			HalconAPI.Store(proc, 1, absThreshold);
			HalconAPI.Store(proc, 2, varThreshold);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(absThreshold);
			HalconAPI.UnpinTuple(varThreshold);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
			GC.KeepAlive(refImage);
			GC.KeepAlive(varImage);
		}

		/// <summary>
		///   Prepare a variation model for comparison with an image.
		///   Instance represents: ID of the variation model.
		/// </summary>
		/// <param name="refImage">Reference image of the object.</param>
		/// <param name="varImage">Variation image of the object.</param>
		/// <param name="absThreshold">Absolute minimum threshold for the differences between the image and the variation model. Default: 10</param>
		/// <param name="varThreshold">Threshold for the differences based on the variation of the variation model. Default: 2</param>
		// Token: 0x06001ABF RID: 6847 RVA: 0x000A5604 File Offset: 0x000A3804
		public void PrepareDirectVariationModel(HImage refImage, HImage varImage, double absThreshold, double varThreshold)
		{
			IntPtr proc = HalconAPI.PreCall(89);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, refImage);
			HalconAPI.Store(proc, 2, varImage);
			HalconAPI.StoreD(proc, 1, absThreshold);
			HalconAPI.StoreD(proc, 2, varThreshold);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
			GC.KeepAlive(refImage);
			GC.KeepAlive(varImage);
		}

		/// <summary>
		///   Prepare a variation model for comparison with an image.
		///   Instance represents: ID of the variation model.
		/// </summary>
		/// <param name="absThreshold">Absolute minimum threshold for the differences between the image and the variation model. Default: 10</param>
		/// <param name="varThreshold">Threshold for the differences based on the variation of the variation model. Default: 2</param>
		// Token: 0x06001AC0 RID: 6848 RVA: 0x000A5664 File Offset: 0x000A3864
		public void PrepareVariationModel(HTuple absThreshold, HTuple varThreshold)
		{
			IntPtr proc = HalconAPI.PreCall(90);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, absThreshold);
			HalconAPI.Store(proc, 2, varThreshold);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(absThreshold);
			HalconAPI.UnpinTuple(varThreshold);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Prepare a variation model for comparison with an image.
		///   Instance represents: ID of the variation model.
		/// </summary>
		/// <param name="absThreshold">Absolute minimum threshold for the differences between the image and the variation model. Default: 10</param>
		/// <param name="varThreshold">Threshold for the differences based on the variation of the variation model. Default: 2</param>
		// Token: 0x06001AC1 RID: 6849 RVA: 0x000A56B4 File Offset: 0x000A38B4
		public void PrepareVariationModel(double absThreshold, double varThreshold)
		{
			IntPtr proc = HalconAPI.PreCall(90);
			base.Store(proc, 0);
			HalconAPI.StoreD(proc, 1, absThreshold);
			HalconAPI.StoreD(proc, 2, varThreshold);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Train a variation model.
		///   Instance represents: ID of the variation model.
		/// </summary>
		/// <param name="images">Images of the object to be trained.</param>
		// Token: 0x06001AC2 RID: 6850 RVA: 0x000A56F8 File Offset: 0x000A38F8
		public void TrainVariationModel(HImage images)
		{
			IntPtr proc = HalconAPI.PreCall(91);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, images);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
			GC.KeepAlive(images);
		}

		/// <summary>
		///   Free the memory of a variation model.
		///   Instance represents: ID of the variation model.
		/// </summary>
		// Token: 0x06001AC3 RID: 6851 RVA: 0x000A5738 File Offset: 0x000A3938
		public void ClearVariationModel()
		{
			IntPtr proc = HalconAPI.PreCall(93);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Free the memory of the training data of a variation model.
		///   Instance represents: ID of the variation model.
		/// </summary>
		// Token: 0x06001AC4 RID: 6852 RVA: 0x000A576C File Offset: 0x000A396C
		public void ClearTrainDataVariationModel()
		{
			IntPtr proc = HalconAPI.PreCall(94);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Create a variation model for image comparison.
		///   Modified instance represents: ID of the variation model.
		/// </summary>
		/// <param name="width">Width of the images to be compared. Default: 640</param>
		/// <param name="height">Height of the images to be compared. Default: 480</param>
		/// <param name="type">Type of the images to be compared. Default: "byte"</param>
		/// <param name="mode">Method used for computing the variation model. Default: "standard"</param>
		// Token: 0x06001AC5 RID: 6853 RVA: 0x000A57A0 File Offset: 0x000A39A0
		public void CreateVariationModel(int width, int height, string type, string mode)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(95);
			HalconAPI.StoreI(proc, 0, width);
			HalconAPI.StoreI(proc, 1, height);
			HalconAPI.StoreS(proc, 2, type);
			HalconAPI.StoreS(proc, 3, mode);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}
	}
}
